#include "vector.h"

float Vector::getNorm() const
{
    return sqrt ( square( getX() ) + square( getY() ) + square( getZ() ) );
}

float Vector::getNormSquared() const
{
    return square( getX() ) + square( getY() ) + square( getZ() );
}

Vector Vector::normalize() const
{
	  if(getX() == 0 && getY() == 0 && getZ() == 0)
		  return *this;

    // variável contendo o valor da norma do vetor
    double norm = getNorm();

    // retorna uma cópia do vetor normalizada
    return Vector( getX() / norm, getY() / norm, getZ() / norm );
}

Vector& Vector::normalizeMe()
{
	  if(getX() == 0 && getY() == 0 && getZ() == 0)
		  return *this;

	 //assert norm != 0
    // variável contendo o valor da norma do vetor
    double norm = getNorm();

    // vetor que será retornado
	  setX(getX() / norm);
	  setY(getY() / norm);
	  setZ(getZ() / norm);

    // retorna o vetor normalizado
    return *this;
}

Vector Vector::crossProduct(const Vector& other)
{
	return Vector( (getY() * other.getZ()) - (getZ() * other.getY()),
				   (getZ() * other.getX()) - (getX() * other.getZ()),
				   (getX() * other.getY()) - (getY() * other.getX()) );

}

float Vector::dotProduct(const Vector& other)
{
	return ( getX() * other.getX() ) +
		   ( getY() * other.getY() ) +
		   ( getZ() * other.getZ() );
}

